﻿using ConfClient;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UtilPublic.Serialization;
using UtilWpf;
using Zpb;

namespace client
{
    /// <summary>
    /// PagePlayer.xaml 的交互逻辑
    /// </summary>
    public partial class PagePlayer : Page
    {
        public PagePlayer()
        {
            InitializeComponent();

            App.PagePlayer = this;
        }
        public void UpdatePage()
        {
            UpdatePlayerJson();
            UpdatePlayerBase();
            UpdatePlayerMisc();
            UpdatePlayerStatus();
            UpdateItemInfo();
            UpdateEquipInfo();
        }
        public void UpdatePlayerJson()
        {
            //TextBoxPlayerJson.Text = Jsh.Jstr(GameData.PlayerInfo);
        }
        public void UpdatePlayerBase()
        {
            ToolHelper.GetFieldsDescList(GameData.PlayerInfoBase, out var ListDatas);
            DataGridInfoBase.BindingObj(ListDatas);
            //DataGridInfoGameMoney.BindingDictObj(GameData.PlayerInfoBase.Moneys.ToDictionary(it => (EMoneyType)it.Key, it => it.Value));
        }
        public void UpdatePlayerMisc()
        {
            ToolHelper.GetFieldsDescList(GameData.PlayerInfoMisc, out var ListDatas);
            DataGridInfoMisc.BindingObj(ListDatas);

            //DataGridInfoMiscflagString.BindingDictObj(GameData.Player.InfoMisc.FlagString.ToDictionary(it => it.Key, it => it.Value));
            //DataGridInfoMiscflagIntInt.BindingDictObj(GameData.Player.InfoMisc.FlagIntInt.ToDictionary(it => it.Key, it => it.Value));
            //DataGridInfoMiscflagIntBool.BindingDictObj(GameData.Player.InfoMisc.FlagIntBool.ToDictionary(it => it.Key, it => it.Value));
            //DataGridInfoMiscflagDailyString.BindingDictObj(GameData.Player.InfoMisc.FlagDailyString.ToDictionary(it => it.Key, it => it.Value));
            //DataGridInfoMiscflagDailyIntInt.BindingDictObj(GameData.Player.InfoMisc.FlagDailyIntInt.ToDictionary(it => it.Key, it => it.Value));
            //DataGridInfoMiscflagDailyIntBool.BindingDictObj(GameData.Player.InfoMisc.FlagDailyIntBool.ToDictionary(it => it.Key, it => it.Value));
        }
        public void UpdatePlayerStatus()
        {
            
        }
        public void UpdateItemInfo()
        {
            //var dict = new Dictionary<string, long>();
            //foreach (var kvp in GameData.ItemInfoList.Items)
            //{
            //    var key = kvp.Key.ToString();
            //    if (Conf.ConfItem.TryGetValue(kvp.Key, out var conf))
            //    {
            //        key = $"{conf.Name} [{kvp.Key}]";
            //    }
            //    dict[key] = kvp.Value;
            //}
            //DataGridInfoGameItem.BindingDictObj(dict);
        }
        public void UpdateEquipInfo()
        {
            //var listnode = ToolHelper.GetUserControlColumnNodeList(new EquipInfo());
            //listnode.Add(new UserControlColumnNode("Name", "Name"));
            //ObservableCollection<ExpandoObject> listdata = new();
            //foreach (var item in GameData.EquipInfoList.Equips.Values)
            //{
            //    dynamic node = new ExpandoObject();
            //    node.Id = item.Id;
            //    node.CfgId = item.CfgId;
            //    node.Level = item.Level;
            //    node.Star = item.Star;
            //    if (Conf.ConfEquip.TryGetValue(item.CfgId, out var conf))
            //    {
            //        node.Name = conf.Name;
            //    }
            //    listdata.Add(node);
            //}
            //DataGridInfoGameEquip.BindingListData(listnode, listdata);
        }
        public void UpdateMailInfoList()
        {
            var listnode = ToolHelper.GetUserControlColumnNodeList(new MailInfo());
            ObservableCollection<ExpandoObject> listdata = new();
            foreach (var item in GameData.MailInfoList.Mails)
            {
                dynamic node = new ExpandoObject();
                node.Id = item.Id;
                node.MailType = item.MailType;
                node.Title = item.Title;
                node.Body = item.Body;
                node.SenderName = item.SenderName;
                node.CreateTime = item.CreateTime;
                node.Read = item.Read;
                node.Got = item.Got;
                node.Awards = item.Awards;
                listdata.Add(node);
            }
            DataGridInfoGameMail.BindingListData(listnode, listdata);
        }
        private void Button_Click_PlayerMail(object sender, RoutedEventArgs e)
        {
            var Content = (sender as Button).Content.ToString();
            switch (Content)
            {
                case "获取邮件列表":
                    {
                        //App.Send(EPid.CgmailListGet);
                    }
                    break;
                case "读一封未读邮件":
                    {
                        foreach (var item in GameData.MailInfoList.Mails)
                        {
                            if (!item.Read)
                            {
                                //MsgString req = new();
                                //req.Value = item.Id;
                                //App.Send(EPid.CgmailRead, req);
                                //break;
                            }
                        }
                    }
                    break;
                case "领一封未领邮件":
                    {
                        foreach (var item in GameData.MailInfoList.Mails)
                        {
                            if (!item.Got)
                            {
                                //MsgString req = new();
                                //req.Value = item.Id;
                                //App.Send(req);
                                //break;
                            }
                        }
                    }
                    break;
                case "删除一封邮件":
                    {
                        foreach (var item in GameData.MailInfoList.Mails)
                        {
                            //MsgString req = new();
                            //req.Value = item.Id;
                            //App.Send(req);
                            //break;
                        }
                    }
                    break;
                case "一键领取":
                    {
                        //App.Send(EPid.CgmailGetAll);
                    }
                    break;
                case "一键删除已读":
                    {
                        //App.Send(EPid.CgmailDeleteAll);
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
